package tool

import (
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"log"
	"newapp/model"
)

var gormDB *gorm.DB

func InitDB() *gorm.DB {
	dsn := "root:123456@tcp(127.0.0.1:3306)/testapp?charset=utf8mb4&parseTime=True&loc=Local"
	db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		log.Fatal(err.Error())
		return nil
	}
	gormDB = db
	_ = db.AutoMigrate(&model.User{})

	return db
}

func GetDB() *gorm.DB {
	return gormDB
}
